package bootstrap

import (
	"context"
	"github.com/go-redis/redis/v8"
	"go-mall/global"
	"go.uber.org/zap"
	"time"
)

func Redis() {
	redisCfg := global.CONFIG.Redis
	client := redis.NewClient(&redis.Options{
		Addr:     redisCfg.Addr,
		Password: redisCfg.Password,
		DB:       redisCfg.DB,
	})
	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()
	pong, err := client.Ping(ctx).Result()
	if err != nil {
		global.LOG.Error("reds连接ping失败,err:", zap.Error(err))
	} else {
		global.LOG.Info("reds连接ping响应:", zap.String("pong", pong))
		global.RedisDB = client
	}

}
